package gui;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import javax.persistence.*;

/**
 * @file Stock.java
 * @version 0.1
 * @author James Dibble 10009689
 */
@Entity
@Table(name = "stock", catalog = "dms", schema = "")
@NamedQueries({
    @NamedQuery(name = "Stock.findAll", query = "SELECT s FROM Stock s"),
    @NamedQuery(name = "Stock.findById", query = "SELECT s FROM Stock s WHERE s.id = :id"),
    @NamedQuery(name = "Stock.findByBatch", query = "SELECT s FROM Stock s WHERE s.batch = :batch"),
    @NamedQuery(name = "Stock.findBySalePrice", query = "SELECT s FROM Stock s WHERE s.salePrice = :salePrice"),
    @NamedQuery(name = "Stock.findByQtyOnHand", query = "SELECT s FROM Stock s WHERE s.qtyOnHand = :qtyOnHand"),
    @NamedQuery(name = "Stock.findByPart", query = "SELECT s FROM Stock s WHERE s.part = :part")})
public class Stock implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id")
    private Integer id;
    @Basic(optional = false)
    @Column(name = "batch")
    private String batch;
    @Basic(optional = false)
    @Column(name = "sale_price")
    private long salePrice;
    @Basic(optional = false)
    @Column(name = "qty_on_hand")
    private int qtyOnHand;
    @Basic(optional = false)
    @Column(name = "part")
    private int part;
    // <editor-fold defaultstate="collapsed" desc="Attributes">
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Constructors">
    public Stock() {
    }
    // </editor-fold>

    // <editor-fold defaultstate="collapsed" desc="Methods">
    // </editor-fold>

    public Stock(Integer id) {
        this.id = id;
    }

    public Stock(Integer id, String batch, long salePrice, int qtyOnHand, int part) {
        this.id = id;
        this.batch = batch;
        this.salePrice = salePrice;
        this.qtyOnHand = qtyOnHand;
        this.part = part;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        Integer oldId = this.id;
        this.id = id;
        changeSupport.firePropertyChange("id", oldId, id);
    }

    public String getBatch() {
        return batch;
    }

    public void setBatch(String batch) {
        String oldBatch = this.batch;
        this.batch = batch;
        changeSupport.firePropertyChange("batch", oldBatch, batch);
    }

    public long getSalePrice() {
        return salePrice;
    }

    public void setSalePrice(long salePrice) {
        long oldSalePrice = this.salePrice;
        this.salePrice = salePrice;
        changeSupport.firePropertyChange("salePrice", oldSalePrice, salePrice);
    }

    public int getQtyOnHand() {
        return qtyOnHand;
    }

    public void setQtyOnHand(int qtyOnHand) {
        int oldQtyOnHand = this.qtyOnHand;
        this.qtyOnHand = qtyOnHand;
        changeSupport.firePropertyChange("qtyOnHand", oldQtyOnHand, qtyOnHand);
    }

    public int getPart() {
        return part;
    }

    public void setPart(int part) {
        int oldPart = this.part;
        this.part = part;
        changeSupport.firePropertyChange("part", oldPart, part);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Stock)) {
            return false;
        }
        Stock other = (Stock) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "gui.Stock[ id=" + id + " ]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
}
